jQuery.noConflict();
var isShowLoginForm = false;
var isShowForgot = false;
var isShowRegisterForm = false;
var isShowPayMentForm = false;

function setVisiblePayMentForm(b){
    if(b){
        jQuery("#PaymentDiv").slideDown("fast", function(){
            isShowPayMentForm = true;
        });
    }else{
        jQuery("#PaymentDiv").slideUp("fast", function(){
            isShowPayMentForm = false;
        });
    }
}

function setVisibleLoginForm(b) {
    if (b) {
        jQuery("#wrapper_row2").css("margin-top",120);
        jQuery("#searchDiv").hide();
        jQuery("#loginDiv").slideDown("slow", function() { 
            jQuery("#wrapper_row2").css("margin-top",120);
            isShowLoginForm = true;
        });
    } else {          
        jQuery("#loginDiv").slideUp("slow", function() {
            jQuery("#wrapper_row2").css("margin-top",0);
            isShowLoginForm = false;
             
        });
        jQuery("#searchDiv").show();
    }
}

function setVisibleRegisterForm(b) {
    if (b) {
       
        jQuery("#wrapper_row2").css("margin-top",200);
        jQuery("#searchDiv").hide();
        jQuery("#RegisterDiv").slideDown("slow", function() {   
            jQuery("#wrapper_row2").css("margin-top",200);
            isShowRegisterForm = true;
        });
    } else {      
        jQuery("#RegisterDiv").slideUp("slow", function() {
            jQuery("#wrapper_row2").css("margin-top",0);
            isShowRegisterForm = false;
             
        });
        jQuery("#searchDiv").show();
    }
}

function openResgisterForm(){
    clearDataRegisterForm();
    clearDataError();
    setVisibleLoginForm(false);
    jQuery("#registerS").html("<h3>Register Form</h3>");
    jQuery("#table_register").show();
    var location = jQuery("#RegisterF").offset();
    var top = parseInt(location.top)+8;
    var left = parseInt(location.left)-250;
    jQuery("#RegisterContainer").css("left", left);
    jQuery("#RegisterContainer").css("top", top);
    if(isShowRegisterForm){
        setVisibleRegisterForm(false);
    }else{
        setVisibleRegisterForm(true);
    }
}

function OpenLoginForm(idDiv){
    clearDataLoginForm();
    setVisibleRegisterForm(false);
    jQuery("#loginDiv").css("height", 140);
    jQuery("#loginDiv").css("width", 417);
    jQuery("#table_login").show("fast"); 
    var location = jQuery("#staLogin").offset();
    var top = parseInt(location.top)+8;
    var left = parseInt(location.left)-510;
    jQuery("#loginContainer").css("left", left);
    jQuery("#loginContainer").css("top", top);
    if(idDiv =='stuLogin'){
        jQuery("#lblInfor").text('Login');
        jQuery("#typeLogin").val("stu");
       
    }
//    else if(idDiv == 'staLogin'){
//        jQuery("#lblInfor").text('Staff Login');
//        jQuery("#typeLogin").val("staff");
//
//    }
    if(isShowLoginForm){
        setVisibleLoginForm(false);
    }else{
        setVisibleLoginForm(true);
    }
    
}

function openForgotPass(){
    if (!isShowForgot) {
        jQuery("#table_login").hide("fast");
        jQuery("#loginDiv").css("height", 100);
        jQuery("#loginDiv").css("width", 300);
        jQuery("#table_forgotPass").show("slow", function() {
            isShowForgot = true;
        });
    } else { 
        jQuery("#table_login").show("fast");
        jQuery("#table_forgotPass").hide("fast", function() {         
            isShowForgot = false;
            jQuery("#loginDiv").css("height", 140);
            jQuery("#loginDiv").css("width", 417);
        });
        
    }
}

function openPaymentForm(id){
    var location = jQuery("#"+id).offset();
    var left = parseInt(location.left);
    var top = parseInt(location.top);
    jQuery("#containerPopUpPayment").css("left",left);
    jQuery("#containerPopUpPayment").css("top",top);
    if(isShowPayMentForm){
        setVisiblePayMentForm(false);
    }else{
        setVisiblePayMentForm(true);
    }
}

function closeLoginForm(){
    clearDataLoginForm();
    setVisibleLoginForm(false);
}

function closeRegisterForm(){
    clearDataRegisterForm();
    setVisibleRegisterForm(false);
}

function drawMenuTopAfterLogin(arrayInfor){
    var html = '<li><a style=\"cursor: pointer;\">Home</a>';
    html = html +'</li><li><a style=\"cursor: pointer;\">Contact Us</a></li>';
    html = html + '<li><a style=\"cursor: pointer;\" title=\"View Profile\"  onclick=\"\">Hi,'+arrayInfor[1] +'!</a></li>';
    html = html + '<li class ="last" ><a style=\"cursor:pointer;\" onclick=\"logout()\">Logout</a></li>';
    html = html +'<li><a style=\"cursor: pointer;\" id=\"RegisterF\" >User Profile</a></li>';
    jQuery("#menu_top").html(html);
}
function logout(){
    drawMenuTop();
}
function drawMenuTop(){
    var html = '<li><a style=\"cursor: pointer;\">Home</a>';
    html = html +'</li><li><a style=\"cursor: pointer;\">Contact Us</a></li>';
    html = html +'<li><a style=\"cursor: pointer;\" id=\"RegisterF\" onclick=\"openResgisterForm()\">Register</a></li>';
    html = html + '<li id=\"stuLogin\"><a style=\"cursor: pointer;\" onclick=\"OpenLoginForm(\'stuLogin\')\">Login</a></li>';
    //html = html + '<li id=\"staLogin\" class=\"last\"><a style=\"cursor: pointer;\" onclick=\"OpenLoginForm(\'staLogin\')\">Staff Login</a></li>';
    
    jQuery("#menu_top").html(html);  
}

function clearDataError(){
     
     jQuery("#errorMail").text('');
     jQuery("#errorPass").text('');
     jQuery("#errorName").text('');
}
function clearDataRegisterForm(){
    
    jQuery("#txtname").val("");
    jQuery("#txtPassword").val("");
    jQuery("#txtEmail").val("");
}

function clearDataLoginForm()
{
    jQuery("#typeLogin").val("");
    jQuery("#txtUsername").val("");
    jQuery("#txtPass").val("");
    
}